<?php
    /**
     * Created by JetBrains NetBeans.
     * User: yinyancai
     * Date: 13-3-14 下午4:44
     * To change this template use File | Settings | File Templates.
     */
    if (!defined('IN_MOBILE_API')) {
        exit('Access Denied');
    }
    include_once 'forum.php';
    class cloud_api {
        function common() { }

        function output() {
            global $_G;
            //判断是否缺少参数
            if (empty($_GET['name']) || empty($_GET['content'])) {
                $variable = array(
                    'code' => 1001,
                    'messagestr' => lang('plugin/cloud', '1001'),
                );
                cloud_core::result(cloud_core::variable($variable));
            }  
            //新增
            $content = $_GET['content'];
            $summarys=strip_tags($content);
            $data = array(
                'ccid' => $_GET['ccid'],
                'name' => $_GET['name'],
                'summary' => strlen($summarys)<100 ? $summarys : self::msubstr($summarys,0,100),
                'picurl' =>  $_GET['picurl'],
                'content' => $content,
                'lasttime' => TIMESTAMP,
                'status'=>$_GET['status'],
                'viewnum' =>0,
                'commentnum'=>0,
            );
            $id = C::t('#cloud#cloud_article')->insert($data);
            //如果插入失败，这返回错误信息 
            if (empty($id)) {
                $variable = array(
                    'code' => 10009,
                    'messagestr' => lang('plugin/cloud', '10009'),
                );
                cloud_core::result(cloud_core::variable($variable));
//            }else{
//                //更新图片关系表 前端返回的图片ID数组
//                $picid_data = '';
//                C::t('#cloud#cloud_article_attachment')->update_artice_pic($id,$picid_data);
            }
            
            //正常返回
            $variable = array(
                'messagestr' => lang('plugin/cloud', '10010'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        function msubstr($str, $start, $len) {
            $tmpstr = "";
            $strlen = $start + $len;
            for($i = 0; $i < $strlen; $i++) {
                if(ord(substr($str, $i, 1)) > 0xa0) {
                    $tmpstr .= substr($str, $i, 2);
                    $i++;
                } else
                    $tmpstr .= substr($str, $i, 1);
            }
            return $tmpstr;
        }
    }

?>

